/**
 * Created by dukes on 2015/12/4.
 */
//module game{
    class PersonalChatItemRender extends eui.ItemRenderer {
        public constructor() {
            super();
            this.skinName = "pet.PersonalChatItemRenderSkin";
        }

        private onTap(evt:egret.TouchEvent) {
            if (evt.target == this.img_close || evt.currentTarget == this.img_close) {
                ChatMgr.getInstance().removeChater(this.data.userId);
                ChatScene.getInstance().updaterProvider();
            } else {
                SceneMgr.getInstance().switchScene(SceneMgr.SCENE_CHAT_P, [this.data]);
            }

        }

        public dataChanged() {
            super.dataChanged();
            this.lab_name.text = LimitStringLen(this.data.name || this.data.userName);
            if( Model.me.platform != PlatformEnum.QQBROWSER){
                this.img_head.source = (this.data.figureurl && this.data.figureurl != "") ? this.data.figureurl : RES.getRes("default_head_0") ;
            }else{
                this.img_head.source = RES.getRes("default_head_"+(this.data.userId%5));
            }

            Model.referDate.setTime(this.data.time);
            var date:Date = Model.referDate;
            this.lab_time.text = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
        }

        private lab_name:eui.Label;
        private lab_time:eui.Label;
        private img_head:eui.Image;
        private img_close:eui.Image;

        public partAdded(name:string, instance:any) {
            super.partAdded(name, instance);
            if (name == "lab_name") {
                this.lab_name = instance;
            } else if (name == "img_head") {
                this.img_head = instance;
            } else if (name == "img_close") {
                this.img_close = instance;
            } else if (name == "lab_time") {
                this.lab_time = instance;
            }
        }

        public childrenCreated(){
            super.childrenCreated();
            this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
    }
}
//}